using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;

namespace ResourceStringsContentByQueryWebPart.WebPartCode
{
    [Guid("40c287cc-653c-47f0-a8f6-77a6d17e24b3")]
    public class ResourceStringContentByQueryWebPart : Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart
    {
        private string resourceStrings = null;

        [WebBrowsable(false), Personalizable(PersonalizationScope.Shared)]
        public string ResourceStrings
        {
            get { return resourceStrings; }
            set { resourceStrings = value; }
        }

        private static string GetString(string s)
        {
            return HttpContext.GetGlobalResourceObject("evideslabels", s, System.Globalization.CultureInfo.CurrentCulture) as string;
        }

        protected override void ModifyXsltArgumentList(ArgumentClassWrapper argList)
        {
            base.ModifyXsltArgumentList(argList);
            if (!string.IsNullOrEmpty(ResourceStrings))
            {
                string[] rstrings = ResourceStrings.Split(';');
                foreach (string rs in rstrings)
                {
                    if (!string.IsNullOrEmpty(rs))
                    {
                        string[] r = rs.Split(',');
                        if (r.Length >= 2)
                        {
                            argList.AddParameter(r[0], string.Empty, GetString(r[1]));
                        }
                    }
                }
            }
            argList.AddParameter("WebUrl2", string.Empty, this.WebUrl);
        }

    }
}
